package com.example.finaltool.utils;

import com.example.finaltool.consts.key.CoreKey;
import com.example.finaltool.consts.key.DataKey;
import com.example.finaltool.model.config.Data;
import com.example.finaltool.model.config.Zhudiwang;
import com.example.finaltool.model.DepInfo;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.lang3.StringUtils;

import java.util.List;
import java.util.Map;

@Slf4j
public class PrintUtils {
    private PrintUtils(){}
    public static void finish() {
        System.out.println(
                " _______  __  .__   __.  __       _______. __    __   _______  _______  \n" +
                "|   ____||  | |  \\ |  | |  |     /       ||  |  |  | |   ____||       \\ \n" +
                "|  |__   |  | |   \\|  | |  |    |   (----`|  |__|  | |  |__   |  .--.  |\n" +
                "|   __|  |  | |  . `  | |  |     \\   \\    |   __   | |   __|  |  |  |  |\n" +
                "|  |     |  | |  |\\   | |  | .----)   |   |  |  |  | |  |____ |  '--'  |\n" +
                "|__|     |__| |__| \\__| |__| |_______/    |__|  |__| |_______||_______/ \n" +
                "                                                                        ");
    }

    public static void start() {
        log.info("-------started---------");
    }

    public static void separator() {
        log.info("-----------------------");
    }

    public static void showCore(Map<String, String> core) {
        KeyUtils.keysOf(CoreKey.class).forEach(k -> {
            if (core.containsKey(k)) {
                log.info(k + ": " + core.get(k));
            } else {
                log.info(k + ": <NotFound>");
            }
        });
        PrintUtils.separator();
    }

    public static void showData(Data data) {
        KeyUtils.keysOf(DataKey.class).forEach(k -> {
            if (DataKey.ZHUDIWANG.equals(k)) {
                if (data.contains(k)) {
                    showZhudiwang(data.getZhudiwang());
                } else {
                    log.info(k + ": <NotFound>");
                }
            } else if (data.contains(k)) {
                log.info(k + ": " + data.getString(k));
            } else {
                log.info(k + ": <NotFound>");
            }
        });
        PrintUtils.separator();
    }

    private static void showZhudiwang(List<Zhudiwang> info) {
        info.forEach(z -> log.info("驻地网: " + z.getCun() + ", " + z.getBianhao() + ", " + z.getId()));
    }

    public static void showExist(String table, String column) {
        log.info("\"" + table + "\" 表中已有 \"" + column + "\"，不会更新此字段");
    }

    public static void showExist(String table) {
        log.info("\"" + table + "\" 表中已有数据，不会更新此字段");
    }

    public static void stepStart(String step) {
        log.info(step + " 开始处理");
    }

    public static void stepFinish(String step) {
        stepFinish(step, null);
    }

    public static void stepFinish(String step, String timeUsed) {
        String res = step + " 处理完成";
        if (StringUtils.isNotBlank(timeUsed)) {
            res += ", 用时" + timeUsed;
        }
        log.info(res);
    }

    public static void showDepInfo(DepInfo info) {
        if (info.getFuwu() != null) {
            log.info("服务支撑人员: " + info.getFuwu());
        } else {
            log.info("服务支撑人员: <NotFound>");
        }
        if (info.getXiangzhen() != null) {
            log.info("乡镇管理人员: " + info.getXiangzhen());
        } else {
            log.info("乡镇管理人员: <NotFound>");
        }
        info.getCunDepInfoList().forEach(c -> log.info(c.getCunName() + ": " + c.getCunDepId() + ", 农户: " + c.getNonghu() + ", 服务支撑人员: " + c.getFuwu()));
        PrintUtils.separator();
    }

    public static void skip(String item) {
        log.info(item + " 不存在，已跳过");
    }
}
